package com.kexio.common.exception;

/**
 * 业务异常
 * 用于处理业务逻辑相关的异常，如参数校验失败、业务规则违反等
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public class BusinessException extends BaseException {
    
    /**
     * 默认业务异常码
     */
    public static final Integer DEFAULT_CODE = 400;
    
    /**
     * 参数验证失败
     */
    public static final Integer VALIDATION_ERROR = 400;
    
    /**
     * 权限不足
     */
    public static final Integer PERMISSION_DENIED = 403;
    
    /**
     * 资源未找到
     */
    public static final Integer NOT_FOUND = 404;
    
    /**
     * 业务规则冲突
     */
    public static final Integer BUSINESS_CONFLICT = 409;
    
    /**
     * 业务规则限制
     */
    public static final Integer BUSINESS_LIMITATION = 422;
    
    public BusinessException(String message) {
        super(DEFAULT_CODE, message);
    }
    
    public BusinessException(Integer code, String message) {
        super(code, message);
    }
    
    public BusinessException(String message, String detail) {
        super(DEFAULT_CODE, message, detail);
    }
    
    public BusinessException(Integer code, String message, String detail) {
        super(code, message, detail);
    }
    
    public BusinessException(String message, Throwable cause) {
        super(DEFAULT_CODE, message, cause);
    }
    
    public BusinessException(Integer code, String message, Throwable cause) {
        super(code, message, cause);
    }
    
    // 快捷创建方法
    
    /**
     * 参数验证异常
     */
    public static BusinessException validationError(String message) {
        return new BusinessException(VALIDATION_ERROR, message);
    }
    
    /**
     * 权限不足异常
     */
    public static BusinessException permissionDenied(String message) {
        return new BusinessException(PERMISSION_DENIED, message);
    }
    
    /**
     * 资源未找到异常
     */
    public static BusinessException notFound(String message) {
        return new BusinessException(NOT_FOUND, message);
    }
    
    /**
     * 业务冲突异常
     */
    public static BusinessException conflict(String message) {
        return new BusinessException(BUSINESS_CONFLICT, message);
    }
    
    /**
     * 业务限制异常
     */
    public static BusinessException limitation(String message) {
        return new BusinessException(BUSINESS_LIMITATION, message);
    }
}
